package com.ruoyi.web.controller.students;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student.domain.StudentsHabits;
import com.ruoyi.student.service.IStudentsHabitsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生习惯信息Controller
 *
 *
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/students/habits")
public class StudentsHabitsController extends BaseController
{
    @Autowired
    private IStudentsHabitsService studentsHabitsService;

    /**
     * 查询学生习惯信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:habits:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentsHabits studentsHabits)
    {
        startPage();
        List<StudentsHabits> list = studentsHabitsService.selectStudentsHabitsList(studentsHabits);
        return getDataTable(list);
    }

    /**
     * 导出学生习惯信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:habits:export')")
    @Log(title = "学生习惯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentsHabits studentsHabits)
    {
        List<StudentsHabits> list = studentsHabitsService.selectStudentsHabitsList(studentsHabits);
        ExcelUtil<StudentsHabits> util = new ExcelUtil<StudentsHabits>(StudentsHabits.class);
        util.exportExcel(response, list, "学生习惯信息数据");
    }

    /**
     * 获取学生习惯信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('students:habits:query')")
    @GetMapping(value = "/{stuId}")
    public AjaxResult getInfo(@PathVariable("stuId") Long stuId)
    {
        return success(studentsHabitsService.selectStudentsHabitsByStuId(stuId));
    }

    /**
     * 新增学生习惯信息
     */
    @PreAuthorize("@ss.hasPermi('students:habits:add')")
    @Log(title = "学生习惯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentsHabits studentsHabits)
    {
        return toAjax(studentsHabitsService.insertStudentsHabits(studentsHabits));
    }

    /**
     * 修改学生习惯信息
     */
    @PreAuthorize("@ss.hasPermi('students:habits:edit')")
    @Log(title = "学生习惯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentsHabits studentsHabits)
    {
        return toAjax(studentsHabitsService.updateStudentsHabits(studentsHabits));
    }

    /**
     * 删除学生习惯信息
     */
    @PreAuthorize("@ss.hasPermi('students:habits:remove')")
    @Log(title = "学生习惯信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{stuIds}")
    public AjaxResult remove(@PathVariable Long[] stuIds)
    {
        return toAjax(studentsHabitsService.deleteStudentsHabitsByStuIds(stuIds));
    }
}
